<!-- 新增修改投标单位 -->
<template>
	<v-forms ref="formRef" :hideFooter="!formState">
		<template #tint1="scope">
			<el-Divider content-position="left" style="margin: 5px 0px"
				><span style="color: #1a63db; font-weight: bold">{{ scope.data.item.label }}</span></el-Divider
			>
		</template>
		<template #File>
			<el-upload :auto-upload="false" v-model:file-list="fileList" multiple :limit="9" :on-change="(file: any, files: any) => { fileChangeHandle(file, files) }">
				<el-button type="primary" >{{ $t('17Y7A6oBxdtEKw6N5W13U') }}</el-button>
			</el-upload>
		</template>
		<!-- <template #Detail>
			<template v-if="formState != 1"
				><el-badge :value="tempCount" type="primary">
					<el-button type="primary" @click="pushFile">{{ $t('tprg1gtr13wMxReXmK14U') }}</el-button>
				</el-badge>
			</template>
		</template> -->
		<v-file-list ref="fileRef" @deleteFile="deleteAction"></v-file-list>
	</v-forms>
</template>
<script lang="ts" setup>
import { ref, Ref } from 'vue';
import { evaluationFormConfig, VForms, evaluationDetailFormConfig } from '../config/form/index';
import { vFileList, getCompleteFileArray, removeData } from '/@/components/ys/index';
import request from '/@/api/common/common';

import useCurrentInstance from '/@/utils/hook/useCurrentInstance';
const { proxy } = useCurrentInstance();
const $t = proxy.$t;

const formRef = ref();
const fileList: any = ref([]);
let currentChangeData: any;
let formState = ref(1);
// 上传文件
const fileChangeHandle = (file: any, files: any[]) => {
	fileList.value = files;
};
const fileRef = ref();
let tempCount = ref(0);
//删除附件
const deleteAction = (ids: any) => {
	//过滤掉被删除的id
	tempCount.value = removeData(currentChangeData.v_FilePath, ids);
};
//附件管理
const pushFile = async () => {
	await fileRef.value.openHandle({
		list: getCompleteFileArray(currentChangeData.v_FilePath),
		canAdd: false,
		canDelete: formState.value == 2,
		deleteFileMethod: request.postDeleteFilesData,
	});
};
//新增数据变更
const addNew = (data: any) => {
	formState.value = 1;
	fileList.value = [];
	let list: any = evaluationFormConfig(data, false);
	formRef.value.openDialog(list, $t('kfR7oKqGr0sNpRoAhHcM'));
};

//修改数据
const change = (data: any) => {
	formState.value = 2;
	fileList.value = [];
	showFile(data);
	let list: any = evaluationFormConfig(data, false);
	formRef.value.openDialog(list, $t('kiUkiqa3h0HLymgh7eEb'));
};

const detail = (data: any) => {
	formState.value = 0;
	fileList.value = [];
	showFile(data);
	let list: any = evaluationDetailFormConfig(data, false);
	formRef.value.openDialog(list, $t('ucC9qxHvkvdh9OGEo1pn'));
};
const showFile = (data: any) => {
	currentChangeData = JSON.parse(JSON.stringify(data));
	tempCount.value = currentChangeData.v_FilePath?.length || 0;
};
defineExpose({
	addNew,
	change,
	detail,
	fileList,
});
</script>
<scope lang="scss" scoped></scope>
